package com.csg.ioms.config;

import com.csg.ioms.handler.CurrUserMethodArgumentResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;

/**
 * <p>
 *  自定义注解 @RequestUser 需要的配置
 * </p>
 *
 * @author GeorgeChan 2020/2/4 13:15
 * @version 1.0
 * @since jdk1.8
 */
@Configuration
public class WebConfigurer extends WebMvcConfigurationSupport {
    /**
     * 其实从这里看出来，与配置在spring-servlet.xml中相比，都是实例化一个自己注解解析器，
     * 然后将它add进spring的List<HandlerMethodArgumentResolver> argumentResolvers中
     * 最后交给spring统一管理
     * @param argumentResolvers
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(currUserMethodArgumentResolver());
        super.addArgumentResolvers(argumentResolvers);
    }

    /**
     * 实例化自己的注解解析器
     * @return
     */
    @Bean
    public CurrUserMethodArgumentResolver currUserMethodArgumentResolver() {
        return new CurrUserMethodArgumentResolver();
    }
}
